//绘制小鱼
var babyObj=function(){
	this.x;
	this.y;
	this.angle;
//	this.babyEye=new Image();
	this.babyBody=new Image();
//	this.babyTail=new Image();
	
	this.babyTailTimer=0;//计时器
	this.babyTailCount=0;//记录当前图片的序号
	
	this.babyEyeTimer=0;
	this.babyEyeCount=0;
	this.babyEyeInterval=1000;//当前这张图片持续多长时间
	
	
	this.babyBodyTimer=0;
	this.babyBodyCount=0;
	
}
babyObj.prototype.init=function(){
	this.x=canWidth*0.5-50;
	this.y=canHeight*0.5+50;
	this.angle=0;
//	this.babyEye.src="src/babyEye0.png";
	this.babyBody.src="src/babyFade0.png";
//	this.babyTail.src="src/babyTail0.png";
	
	
}
babyObj.prototype.draw=function(){
	//lerp让小鱼的坐标一直趋向于大鱼的坐标
	this.x=lerpDistance(mom.x,this.x,0.98);
	this.y=lerpDistance(mom.y,this.y,0.98);
	
	//lerpAngle小鱼的角度跟随大鱼的角度
	var deltaY=mom.y-this.y;
	var deltaX=mom.x-this.x;
	var beta=Math.atan2(deltaY,deltaX)+Math.PI;
	this.angle=lerpAngle(beta,this.angle,0.6);
	
	
	//小鱼尾巴的计时工作
	this.babyTailTimer+=deltaTime;
	if (this.babyTailTimer>50) {
		this.babyTailCount=(this.babyTailCount+1)%8;
		this.babyTailTimer %= 50;
	}
	
	//小鱼眼睛的计时
	this.babyEyeTimer+=deltaTime;
	if (this.babyEyeTimer>this.babyEyeInterval) {
		
		this.babyEyeCount=(this.babyEyeCount+1)%2;
		this.babyEyeTimer%=this.babyEyeInterval;
		
		if (this.babyEyeCount==0) {
			//如果小鱼睁着眼睛，那么我们需要他睁着眼睛的时间为2000~3500
			this.babyEyeInterval=Math.random()*1500+2000;
			
		}else {this.babyEyeInterval=200;//如果小鱼闭着眼睛，那么我们需要他闭着眼睛的时间为200
	}
			
	}
	//babyBody
	this.babyBodyTimer+=deltaTime;
	if (this.babyBodyTimer>300) {
		
		this.babyBodyCount=this.babyBodyCount+1;
		this.babyBodyTimer%=300;
		if (this.babyBodyCount>19) {
			
			this.babyBodyCount=19;
			//game  over
			data.gameOver=true;
		}
	}
	
	ctx1.save();
	ctx1.translate(this.x,this.y);
	ctx1.rotate(this.angle);
	
	var  babyTailCount=this.babyTailCount;
	ctx1.drawImage(babyTail[babyTailCount],-babyTail[babyTailCount].width*0.5+23,-babyTail[babyTailCount].height*0.5);
//	ctx1.drawImage(this.babyTail,-this.babyTail.width*0.5+23,-this.babyTail.height*0.5);
	
	var babyBodyCount=this.babyBodyCount;
	ctx1.drawImage(babyBody[babyBodyCount],-babyBody[babyBodyCount].width*0.5,-babyBody[babyBodyCount].height*0.5);

    var babyEyeCount=this.babyEyeCount;
	ctx1.drawImage(babyEye[babyEyeCount],-babyEye[babyEyeCount].width*0.5,-babyEye[babyEyeCount].height*0.5);
	ctx1.restore();
}
